#include <stdio.h>

union test
{
	char a;
	int  b;
	long c;
};

typedef union{
    struct
    {
        unsigned char reserved:6;
        unsigned char right_dac_power_ctrl:1;
        unsigned char left_dac_power_ctrl:1;
    }bit;
    unsigned char b8;
}dac_power_ctrl;

int main()
{
	union test tt;

	printf("tt sizeof = %d\n\n", sizeof(union test));	// 8
	
	tt.a = 'a';
	printf("%c\n", tt.a);			// a
	printf("%c\n", tt.b);			// a
	printf("%c\n", (int)tt.c);		// a
	printf("union = %c\n\n", tt);	// a
	
	tt.b = 100;
	printf("%d\n", tt.a);			// 100
	printf("%d\n", tt.b);			// 100
	printf("%d\n", (int)tt.c);		// 100
	printf("union = %d\n\n", tt);	// 100
	
	tt.a = 'a';
	printf("%c\n", tt.a);			// a
	printf("%c\n", tt.b);			// a
	printf("%c\n", (int)tt.c);		// a
	printf("union = %c\n\n", tt);	// a
	
	tt.c = 20000;
	printf("%d\n", (char)tt.a);		// 32
	printf("%d\n", (int)tt.b);		// 20000
	printf("%ld\n", tt.c);			// 20000
	printf("union = %ld\n\n", tt);	// 20000
	
	tt.c = 3000;
	printf("%d\n", tt.c);			// 3000
	tt.a = 'b';
	printf("%c\n", tt.a);			// b
	printf("%c\n", tt.c);			// b
	printf("%d\n", tt.c);			// 2914

	printf("union size : %d\n", sizeof(dac_power_ctrl));	// 1
	
	return 0;
}

